package
core {
import com.greensock.TweenLite;

import flash.display.Sprite;
import flash.display.Stage;

import ru.cjay.loading.ResourceManager;


public class Facade {
    private static var _instance:Facade;
    private static var allowInstantiation:Boolean;

    private static var _fade_fog:Sprite;


    public static const WIDTH:int = 668;
    public static const HEIGHT:int = 668;

    public static var RESOURCE_MANAGER:ResourceManager;

    public var MAXWIDTH:int = 668;
    public var MAXHEIGHT:int = 668;
    public var selected_monetype:String = "cash";

    public var stage:Stage;
    public var id_vkontakte:String = null;
    public var auth_key:String = null;

    public static function getInstance():Facade {
        if (_instance == null) {
            allowInstantiation = true;
            _instance = new Facade();
            allowInstantiation = false;
        }
        return _instance;
    }

    public function fadeIn(full:Boolean = false):void {
        _fade_fog.alpha = 0;
        stage.addChild(_fade_fog);
        if (full)         TweenLite.to(_fade_fog, 0.2, {alpha:1});
        else TweenLite.to(_fade_fog, 0.2, {alpha:0.6});

    }

    public function fadeOut():void {

        TweenLite.to(_fade_fog, 0.2, {alpha:0,onComplete:function():void {
                    if (stage.contains(_fade_fog)) stage.removeChild(_fade_fog);
                }
                });
    }

//    This function return string as http GET-parameters, including id_vkontakte and auth_key options
    public function authUrlParams():String {
        return "id_vkontakte=" + id_vkontakte + "&auth_key=" + auth_key + "&timestamp=" + String(new Date().getTime());
    }

    public function Facade() {
        if (!allowInstantiation) {
            throw new Error("Error: Instantiation failed. Use Facade.getInstance instead of new.")
        }
        RESOURCE_MANAGER = ResourceManager.getInstance();

        _fade_fog = new Sprite();
        _fade_fog.graphics.beginFill(0x000000);
        _fade_fog.graphics.drawRect(0, 0, Facade.WIDTH, Facade.HEIGHT);
        _fade_fog.graphics.endFill();
    }
}
}